package foc.physics.solver;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


public class CustomAdapter<T extends CharSequence> extends ArrayAdapter<CharSequence> {
    Context context;
    T[] items;
    int id;

    public CustomAdapter(final Context context,
                         final int textViewResourceId, final T[] objects) {
        super(context, textViewResourceId, objects);
        this.items = objects;
        this.context = context;
        this.id = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(
                    id, parent, false);
        }

        TextView view = (TextView) convertView.findViewById(android.R.id.text1);
        view.setText(items[position]);

        return convertView;
    }
}
